package com.swsc.solarverse.model.req;

import com.swsc.solarverse.common.enums.FaultCategoryEnum;
import com.swsc.solarverse.common.util.BizAssert;
import com.swsc.solarverse.common.util.LocalDateTimeUtils;
import com.swsc.solarverse.common.util.RegexUtils;
import com.swsc.solarverse.model.base.BasePageQueryReqVO;
import com.swsc.solarverse.model.base.BaseQueryReqVO;
import org.apache.commons.collections4.CollectionUtils;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * @Author anonymous
 * @Date 2022/7/5 11:02
 * @Version 1.0
 * @Description DefectQueryReqVO
 */
//@io.swagger.annotations.ApiModel
@lombok.Data
public class DefectQueryReqVO extends BasePageQueryReqVO {
//    @io.swagger.annotations.ApiModelProperty(value = "巡检时间")
    private String patrolTime;

//    @io.swagger.annotations.ApiModelProperty(value = "开始时间")
    private LocalDateTime patrolStartTime;
//    @io.swagger.annotations.ApiModelProperty(value = "结束时间")
    private LocalDateTime patrolEndTime;
//    @io.swagger.annotations.ApiModelProperty(value = "故障状态")
    private String faultStatus;
    private String state;
//    @io.swagger.annotations.ApiModelProperty(value = "故障名称")
    private String faultName;
    private List<String> faultNameIn;
    private String faultNameInStr;
//    @io.swagger.annotations.ApiModelProperty(value = "故障编号")
    private String faultNo;
    private List<String> faultNoIn;
    private String faultNoInStr;
//    @io.swagger.annotations.ApiModelProperty(value = "故障等级")
    private String faultLevel;
//    @io.swagger.annotations.ApiModelProperty(value = "设备编码")
    private String deviceCode;
//    @io.swagger.annotations.ApiModelProperty(value = "区域")
    private String zone;

//    @io.swagger.annotations.ApiModelProperty(value = "重复次数")
    private Integer repeatTimes;

//    @io.swagger.annotations.ApiModelProperty(value = "故障编号")
    private List<Integer> defectIdIn;

//    @io.swagger.annotations.ApiModelProperty(value = "消缺时间")
    private String dealTime;

    private String processState;

//    @io.swagger.annotations.ApiModelProperty(value = "类型: IR; EL; IV; IR,EL; IR,IV; EL,IV; IR,EL,IV")
    private List<String> faultCategoryIn;

    private String taskActualEndTime;
    private List<String> tboxsCodeIn;
    private List<String> invertersCodeIn;
    private Byte detectRangeType;
    public void transformPatrolTime() {
        if (null != patrolTime && RegexUtils.matchAllDateTime(patrolTime) && null == patrolStartTime && null == patrolEndTime) {
            String ptStr = patrolTime.substring(0, 10);
            LocalDateTime ldt = LocalDateTimeUtils.str2Time(ptStr);
            patrolStartTime = LocalDateTimeUtils.getDayStart(ldt);
            patrolEndTime = LocalDateTimeUtils.getDayEnd(ldt);
            patrolTime = null;
        }
    }


    public List<String> getFaultCategoryIn() {
        return null == faultCategoryIn ? Arrays.asList(FaultCategoryEnum.IR.getCode()) : faultCategoryIn;
    }

    public BaseQueryReqVO trans2BaseQueryReqVoByUser() {
        BaseQueryReqVO baseQueryReqVo = this.map(BaseQueryReqVO.class);
        baseQueryReqVo.setTenantNo(getUserTenantNo());
        baseQueryReqVo.setOrganNo(null);
        baseQueryReqVo.setOrganNoIn(null);
        return baseQueryReqVo;
    }

    public void validAppCommonCondition() {
        BizAssert.isFalse(null == getOrganNo() && CollectionUtils.isEmpty(getOrganNoIn()), "组织机构编号不能为空");
        BizAssert.isFalse(CollectionUtils.isEmpty(getFaultCategoryIn()), "故障类别不能为空");
    }

}
